package com.vids.service.impl;

import com.vids.utils.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vids.mapper.ImageMapper;
import com.vids.model.entity.ImageBusiness;
import com.vids.model.vo.ImageVo;
import com.vids.model.vo.SubImageInfoVo;
import com.vids.mapper.ImageBusinessMapper;
import com.vids.service.IImageBusinessService;
import com.vids.service.IImageService;
import com.vids.utils.DateTransUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 图片和业务对于关系 服务实现类
 * </p>
 *

 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ImageBusinessServiceImpl extends ServiceImpl<ImageBusinessMapper, ImageBusiness> implements IImageBusinessService {


    private final ImageMapper iImageService;

    @Override
    public void deleteImageBusiness(ImageBusiness tBigDataImageBusiness) {
        baseMapper.deleteByYwIdAndImageType(tBigDataImageBusiness);
    }

    @Override
    public List<SubImageInfoVo> findSubImageInfoVo(String ywId, String imageType) {
        List<SubImageInfoVo> list = new ArrayList<>();
        ImageBusiness tBigDataImageBusiness = new ImageBusiness();
        tBigDataImageBusiness.setYwId(ywId);
        tBigDataImageBusiness.setBigType(imageType);
        List<ImageBusiness> imageBusinesslist = baseMapper.findByYwIdAndImageType(tBigDataImageBusiness);
        if (imageBusinesslist != null && !imageBusinesslist.isEmpty()) {
            for (ImageBusiness imageBusiness : imageBusinesslist) {
                if (StringUtils.isEmpty(imageBusiness.getImageId())) {
                    continue;
                }
                ImageVo imageVo = iImageService.findDataByImageID(imageBusiness.getImageId());
                if (imageVo == null) {
                    continue;
                }
                SubImageInfoVo subImageInfoVo = new SubImageInfoVo();
                subImageInfoVo.setImageID(imageVo.getImageID());
                subImageInfoVo.setEventSort(imageVo.getEventSort());
                subImageInfoVo.setDeviceID(imageVo.getDeviceID());
                subImageInfoVo.setStoragePath(imageVo.getStoragePath());
                subImageInfoVo.setFileFormat(imageVo.getFileFormat());
                subImageInfoVo.setShotTime(DateTransUtils.timeTrans(imageVo.getShotTime()));
                subImageInfoVo.setWidth(imageVo.getWidth());
                subImageInfoVo.setHeight(imageVo.getHeight());
                subImageInfoVo.setData(imageVo.getData());
                subImageInfoVo.setType(imageBusiness.getImageType());

                list.add(subImageInfoVo);
            }
        }
        return list;
    }
}
